<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <div class="contentsize">委托运营房产情况报表</div>
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <el-form ref="form" :model="form" :inline="true" size="mini">
                    <!-- <el-form-item label="受托单位:">
                        <div style="width: 400px;">
                            <el-select v-model="form.stdwid" placeholder="请选择受托单位" clearable @change="onSearch"
                                :disabled="showlist" style="width: 100%;" filterable>
                                <el-option v-for="item in wtyytableData" :key="item.value" :label="item.stdwmc"
                                    :value="item.stdwid">
                                </el-option>
                            </el-select>
                        </div>

                    </el-form-item> -->
                    <el-form-item label="受托单位:" v-if="!showlist">
                        <div style="width:170px">
                            <el-input v-model="form.stdwmc" placeholder="请输入受托单位" @keyup.enter.native="onSearch" ></el-input>
                        </div>
                    </el-form-item>
                    <el-form-item label="年:">
                        <div style="width:170px">
                            <el-input v-model="form.year" placeholder="请输入年" @keyup.enter.native="onSearch"></el-input>
                        </div>
                    </el-form-item>
                    <el-form-item label="月:">
                        <el-input v-model="form.month" placeholder="请输入月" @keyup.enter.native="onSearch"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="onSearch" icon="el-icon-search" class="searchcolor">查询</el-button>
                        <el-button @click="reSearch" class="searchcolor" icon="el-icon-refresh">重置</el-button>
                        <el-button type="primary" @click="addbaobiao" class="searchcolor" icon="el-icon-plus" v-if="showlist">新增</el-button>
                    </el-form-item>
                </el-form>
            </div>
            <!-- max-height="280" -->
            <el-table :data="tableData" style="width: 100%" :header-cell-style="tableHeaderColor" :row-style="tablerowColor"
                :row-class-name="tableRowClassName" :cell-style="tablecellColor" border :max-height="maxHeight">
                <el-table-column type="index" width="50" label="序号" align="center"></el-table-column>
                <el-table-column label="委托单位名称" align="center" prop="stdwmc"></el-table-column>
                <el-table-column label="年" align="center" prop="year"></el-table-column>
                <el-table-column label="月" align="center" prop="month"></el-table-column>
                <el-table-column label="创建时间" align="center" prop="create_time">
                    <template slot-scope="scope">
                        {{ scope.row.create_time? scope.row.create_time.split(' ')[0]:''}}
                    </template>
                </el-table-column>
                <el-table-column label="操作" width="160" align="center">
                    <template slot-scope="scope">
                        <router-link :to="{ name: 'baobiaodetail', params: { id: scope.row.id } }">
                            <el-button type="text" size="small">查看</el-button>
                        </router-link>
                        <el-button type="text" size="small" @click="deleteClick(scope.row)"
                            style="color: red;margin-left: 20px;" v-if="!showlist">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination" style="float: right">
                <el-pagination background layout="total,prev, pager, next,jumper" :total="total"
                    :current-page.sync="current" :page-size="pageSize" @current-change="handleCurrentChange">
                </el-pagination>
            </div>
        </div>
    </div>
</template>
<script>
import { wtbblist, wtyylist,wtbbdelete } from '@/api/index';
export default {
    name: 'baobiaolist',
    data() {
        return {
            // 报表列表
            tableData: [],
            // 委托运营列表
            wtyytableData: [],
            form: {
                current: 1,
                pageSize: 10,
                stdwid: this.$store.getters.company ? (this.$store.getters.company != 'null' ? this.$store.getters.company : '') : '',
                stdwmc: '',
                year: "",
                month: '',
                zt: ""
            },
            wtyyform: {
                cb: '',//产别 ,
                cqdw: '',//产权单位 ,
                create_time: '',//创建时间 ,
                current: 1,//第几页 ,
                dabh: '',//档案编号 ,
                fwdz: '',//地址 ,
                id: '',//id ,
                jyzt: '',//经营状态 0：招租中 1：出租 ,
                jzmj: '',//建筑面积 ,
                pageSize: 999,//每页数量 ,
                qs: '',//区属 ,
                stdwid: this.$store.getters.company ? (this.$store.getters.company != 'null' ? this.$store.getters.company : '') : '',//受托单位ID
            },
            total: 0,
            current: 1,
            pageSize: 10,
            showlist: false,
            maxHeight:null
        }
    },
    methods: {
        // 列表样式
        tableHeaderColor({ row, column, rowIndex, columnIndex }) {
            if (rowIndex === 0) {
                return 'background:linear-gradient(to bottom, #008A94,#0ae2f2) !important;color:#ffffff;font-size:14px;'
            }
        },
        tablerowColor({ row, rowIndex }) {
            return 'height: 42px;font-size:14px;color:black'
        },
        tablecellColor() {
            return "font-weight:700;color:#000000;border-color:#c0c0c0";
        },
        tableRowClassName({ row, rowIndex }) {
            if (rowIndex % 2 != 0) {
                return 'success-row' //这是类名
            } else {
                return ''
            }
        },
        // 删除
        deleteClick(e) {
            console.log(e);
            this.$confirm('确定删除此条信息吗？')
                .then(() => {
                    let data = { id: e.id };
                    wtbbdelete(data).then((res) => {
                        if (res.code == 200) {
                            this.wtbblist(this.form);
                            this.$message.success('删除成功');
                        }
                    });
                })
                .catch(() => {
                    this.$message.success('删除取消');
                });
        },
        // 委托报表列表
        wtbblist(data) {
            wtbblist(data).then(res => {
                if (res.code == 200) {
                    this.tableData = res.data.records;
                    this.total = res.data.total;
                } else {
                    this.tableData = [];
                    this.total = 0;
                }

            })
        },
        // 换页
        handleCurrentChange(val) {
            this.current = val;
            this.form.current = val;
            this.wtbblist(this.form);
            console.log(val);
        },
        // 搜索
        onSearch() {
            this.current = 1;
            this.form.current = 1;
            this.wtbblist(this.form);
            console.log('搜索');
        },
        // 重置
        reSearch() {
            this.current = 1;
            this.form = {
                current: 1,
                pageSize: 10,
                stdwid: this.$store.getters.company ? (this.$store.getters.company != 'null' ? this.$store.getters.company : '') : '',
                stdwmc: '',
                year: "",
                month: '',
                zt: ""
            };
            this.wtbblist(this.form);
            console.log('重置');
        },
        // 委托运营列表
        wtyylist(data) {
            wtyylist(data).then((res) => {
                var that = this
                if (res.code == 200) {
                    this.wtyytableData = res.data.records;
                    if (this.$store.getters.company && this.$store.getters.company != 'null') {
                        that.showlist = true
                    }
                } else {
                    this.tableData = [];
                }
            });
        },
        // 新增报表
        addbaobiao() {
            this.$router.push({
                name: 'addbaobiaolist',
                path: '/addbaobiaolist'
            });
        }
    },
    mounted() {
        this.$nextTick(() => {
            // window.innerHeight 浏览器窗口的可见高度，下面的 420 是除了table最大高度的剩余空间。
            this.maxHeight = window.innerHeight - 360
        })
        // 委托运营列表
        this.wtyylist(this.wtyyform)
        // 报表列表
        this.wtbblist(this.form);
    }
}
</script>
<style scoped>
.container {
    /* height: calc(100vh - 260px); */
    overflow: hidden;
}

.crumbs {
    background-color: #fff;
    padding: 20px 20px;
}

.indexTitle {
    margin-bottom: 20px;
}

.contentsize {
    font-size: 18px;
    font-weight: 700;
}

.handle-box {
    overflow: hidden;
}
</style>